﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace HML.Design
{
    /// <summary>
    /// 透明颜色预览效果控件
    /// </summary>
    [ToolboxItem(false)]
    public class AlphaColorEditorEffectLabel : Label
    {
        #region 属性

        /// <summary>
        /// 颜色
        /// </summary>
        public Color ColorValue { get; set; }

        /// <summary>
        /// 颜色透明度
        /// </summary>
        public int ColorAlpha { get; set; }

        #endregion

        public AlphaColorEditorEffectLabel()
        {
            this.SuspendLayout();
            this.AutoSize = false;
            this.BackColor = Color.White;
            this.TextAlign = ContentAlignment.MiddleCenter;
            this.ResumeLayout();
        }

        #region 重写

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            SolidBrush color_sb = new SolidBrush(this.ColorValue);

            Region color_r = new Region(e.ClipRectangle);
            GraphicsPath color_gp = new GraphicsPath();
            color_gp.AddEllipse(new Rectangle(e.ClipRectangle.X + 3, e.ClipRectangle.Y + 3, e.ClipRectangle.Width - 6, e.ClipRectangle.Height - 6));
            color_r.Exclude(color_gp);
            e.Graphics.FillRegion(color_sb, color_r);
            color_r.Dispose();
            color_gp.Dispose();

            color_sb.Color = Color.FromArgb(this.ColorAlpha, this.ColorValue);
            e.Graphics.FillEllipse(color_sb, new Rectangle(e.ClipRectangle.X + 3, e.ClipRectangle.Y + 3, e.ClipRectangle.Width - 6, e.ClipRectangle.Height - 6));
            
            color_sb.Dispose();

            Pen color_pen = new Pen(Color.FromArgb(224, 224, 224));
            e.Graphics.DrawRectangle(color_pen, new Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 1));
            color_pen.Dispose();
        }

        #endregion
    }


}
